// pages/techingPositions/jobRecruit/jobRecruit.js
import util from "../../../utils/util.js"
Page({
  /**
   * 页面的初始数据
   */
//   observers: {
//     'dataList_area': function(dataList_area) {
//         const firstList_area = [];
//         for (let item in this.properties.dataList_area) {
//             firstList_area.push(item);
//         }

//         const orignFirstValue_area = firstList_area[0];
//         var secondList_area = this.properties.dataList_area[orignFirstValue_area];
//         if(secondList_area==undefined)
//         {
//             secondList_area=[]
//         }
//         const orignSecondValue_area = secondList_area[0];

//         // 在组件实例进入页面节点树时执行
//         this.setData({
//             firstList_area: firstList_area,
//             secondList_area: secondList_area,

//             orignFirstIdx_area: 0,
//             orignFirstValue_area: orignFirstValue_area,
//             orignSecondIdx_area: 0,
//             orignSecondValue_area: orignSecondValue_area,

//             currentFirstvalue_area: orignFirstValue_area,
//             currentSecondvalue_area: orignSecondValue_area,


//         })
//     }
// },
  data: {
    showSearch: true, // 是否显示搜索框
    list: [],
    searched: false,  //表示当前是否处于搜索状态
    no_more: false, //是否有更多数据？默认为false
            size: 5,
            step: 0,
            popupShow: true, //弹出层是否[可以]显示
            inputValue: '',
            dataList_area: {
                '': []
            },
            firstList_area: [],
            secondList_area: [],
            originFirstIdx_area: 0,
            originSecondIdx_area: 0,
            originFirstValue: "",
            originSecondValue: "",
            //需请求云函数动态传入！
            //格式如下:
            // dataList_area: {
            //     '广州市': ['不限', '越秀区', '海珠区', '荔湾区', '天河区', '白云区', '黄埔区', '花都区', '番禺区', '南沙区', '从化区', '增城区'],
            //     '重庆市': [],
            //     '长春市': [],
            //     '成都市': [],
            //     '长沙市': [],
            //     '大连市': [],
            //     '不限': []
            // },
            dataList_position: {
                '不限': [],
                '幼儿园': ['不限', '专任老师', '其他老师'],
                '小学': ['不限', '语文老师', '数学老师', '英语老师', '音乐老师', '体育老师', '美术老师', '科学老师', '心理健康老师', '信息技术老师', '其他老师'],
                '初中': ['不限', '语文老师', '数学老师', '英语老师', '物理老师', '化学老师', '生物老师', '历史老师', '政治老师', '地理老师', '音乐老师', '体育老师', '美术老师', '道德与法治', '心理健康老师', '信息技术老师', '通用技术老师', '其他老师'],
                '高中': ['不限', '语文老师', '数学老师', '英语老师', '物理老师', '化学老师', '生物老师', '历史老师', '政治老师', '地理老师', '音乐老师', '体育老师', '美术老师', '道德与法治', '心理健康老师', '信息技术老师', '通用技术老师', '其他老师'],
                // '高职': ['不限', '语文老师', '数学老师', '英语老师', '思想品德老师', '科学技术老师'],
                '中学': ['不限', '语文老师', '数学老师', '英语老师', '物理老师', '化学老师', '生物老师', '历史老师', '政治老师', '地理老师', '音乐老师', '体育老师', '美术老师', '道德与法治', '心理健康老师', '信息技术老师', '通用技术老师', '其他老师'],
                '中小学': ['不限', '语文老师', '数学老师', '英语老师', '物理老师', '化学老师', '生物老师', '历史老师', '政治老师', '地理老师', '音乐老师', '体育老师', '美术老师', '道德与法治', '心理健康老师', '信息技术老师', '通用技术老师', '其他老师'],
                '职校': ['职校老师'],
                '特殊教育': ['特殊教育老师'],
                '其他': ['其他老师']

            },
            filterArray_apply: [{
                    title: '报名方式',
                    buttonList: ['不限', '在线报名', '现场报名']
                },
                {
                    title: '报名时间',
                    buttonList: ['不限', '正在报名', '即将报名', '结束报名']
                }
            ],
            filterArray_more: [{
                    title: '编制',
                    buttonList: ['不限', '编制内', '编制外']
                },
                {
                    title: '发布时间',
                    buttonList: ['不限', '今天', '最近7天', '最近1个月', '最近3个月', '最近1年', ]
                }

            ],
            //用于请求云函数的筛选参数,记录当前页面已经选择了哪个筛选项
            filterOptions: {
                city: '', //市
                district: '', //区
                post_level: '', //岗位等级
                subject: '', //科目
                registration_way: '', //报名方式
                has_organized: '', //是否有编制
                stage: '', //报名阶段
                choosetime: 0 //发布时间    
            },
            curPosition: {
                province: "广东省",
                city: "广州市"
            },
    nav2List: [
      { name: '区域', icon: '/assets/techingPositions/ArrowDownAlpha.png' },
      { name: '岗位', icon: '/assets/techingPositions/ArrowDownAlpha.png' },
      { name: '编制', icon: '/assets/techingPositions/ArrowDownAlpha.png' },
      { name: '更多', icon: '/assets/techingPositions/FilterAlpha.png' },
    ],
    nav2Activate: -1,
    // 排序弹窗数据
    sortList: [
      {
        title: '综合排序',
        key: 0,
      },
      {
        title: '浏览量降序',
        key: 1,
      },
      {
        title: '浏览量升序',
        key: 2,
      },
      {
        title: '报名开始时间降序',
        key: 3,
      },
      {
        title: '报名开始时间升序',
        key: 4,
      },
      {
        title: '报名截止时间降序',
        key: 5,
      },
      {
        title: '报名截止时间升序',
        key: 6,
      },
    ],
    showSort: false, // 是否显示排序弹窗
    sortActivate: 0, // 排查选中项
    regionChoose: {
      one: 1,
      two: 1,
    },
    region: '广州市/天河区',
    // 岗位数据
    positionList:{
      '不限': [],
      '幼儿园': ['不限', '专任老师', '其他老师'],
      '小学': ['不限', '语文老师', '数学老师', '英语老师', '音乐老师', '体育老师', '美术老师', '科学老师', '心理健康老师', '信息技术老师', '其他老师'],
      '初中': ['不限', '语文老师', '数学老师', '英语老师', '物理老师', '化学老师', '生物老师', '历史老师', '政治老师', '地理老师', '音乐老师', '体育老师', '美术老师', '道德与法治', '心理健康老师', '信息技术老师', '通用技术老师', '其他老师'],
      '高中': ['不限', '语文老师', '数学老师', '英语老师', '物理老师', '化学老师', '生物老师', '历史老师', '政治老师', '地理老师', '音乐老师', '体育老师', '美术老师', '道德与法治', '心理健康老师', '信息技术老师', '通用技术老师', '其他老师'],
      // '高职': ['不限', '语文老师', '数学老师', '英语老师', '思想品德老师', '科学技术老师'],
      '中学': ['不限', '语文老师', '数学老师', '英语老师', '物理老师', '化学老师', '生物老师', '历史老师', '政治老师', '地理老师', '音乐老师', '体育老师', '美术老师', '道德与法治', '心理健康老师', '信息技术老师', '通用技术老师', '其他老师'],
      '中小学': ['不限', '语文老师', '数学老师', '英语老师', '物理老师', '化学老师', '生物老师', '历史老师', '政治老师', '地理老师', '音乐老师', '体育老师', '美术老师', '道德与法治', '心理健康老师', '信息技术老师', '通用技术老师', '其他老师'],
      '职校': ['职校老师'],
      '特殊教育': ['特殊教育老师'],
      '其他': ['其他老师']
    },
    positionList1: [
      { name: '不限', key: 1 },
      { name: '幼儿园', key: 2 },
      { name: '小学', key: 3 },
      { name: '初中', key: 4 },
      { name: '高中', key: 5 },
      { name: '中学', key: 6 },
      { name: '大学', key: 7 },
      { name: '1', key: 8 },
    ],
    positionList2: [
      { name: '不限', key: 1 },
      { name: '语文老师', key: 2 },
      { name: '数学老师', key: 3 },
      { name: '英语老师', key: 4 },
      { name: '心理健康老师', key: 5 },
      { name: '信息技术老师', key: 6 },
      { name: '老师1', key: 7 },
      { name: '老师2', key: 8 },
    ],
    positionChoose: {
      one: 1,
      two: 1,
    },
    position: '不限',
    // 编制数据
    organizationList: [
      {
        title: '编制',
        key: '不限',
        children: [
          { name: '不限' },
          { name: '编制内' },
          { name: '编制外' }
        ],
      },
    ],
    // 更多数据
    moreList: [
      {
        title: '发布时间',
        key: '不限时间',
        children: [
          { name: '不限时间' },
          { name: '今天' },
          { name: '近一周' },
          { name: '近一个月' },
          { name: '近三个月' },
          { name: '近一年' },
        ],
      },
      {
        title: '报名方式',
        key: '不限方式',
        children: [
          { name: '不限方式' },
          { name: '在线报名' },
          { name: '现场报名' },
        ],
      },
      {
        title: '报名状态',
        key: '不限状态',
        children: [
          { name: '不限状态' },
          { name: '正在报名' },
          { name: '即将报名' },
          { name: '结束报名' },
        ],
      },
    ],
  },

  //地域筛选监听
  tapFirstColumn(e) {
    const currentFirstIdx = e.currentTarget.dataset.index;
    const currentFirstvalue = e.currentTarget.dataset.value;
    const secondList = this.properties.dataList_area[currentFirstvalue];
    
    this.setData({
        currentFirstIdx: currentFirstIdx,
        currentFirstvalue: currentFirstvalue,
        secondList: secondList,
        currentSecondIdx: 0,
        currentSecondvalue: secondList[0]

    })
    console.log("data:",this.data)
},
tapSecondColumn(e) {
  const currentSecondIdx = e.currentTarget.dataset.index;
  const currentSecondvalue = e.currentTarget.dataset.value;
  this.setData({
      currentSecondIdx: currentSecondIdx,
      currentSecondvalue: currentSecondvalue
  })
},
//岗位筛选监听
tapFirstColumn_position(e) {
  const currentFirstIdx = e.currentTarget.dataset.index;
  const currentFirstvalue = e.currentTarget.dataset.value;
  const secondList = this.properties.dataList_position[currentFirstvalue];
  
  this.setData({
      currentFirstIdx_position: currentFirstIdx,
      currentFirstvalue_position: currentFirstvalue,
      secondList_position: secondList,
      currentSecondIdx_position: 0,
      currentSecondvalue_position: secondList[0]

  })
},
tapSecondColumn_position(e) {
const currentSecondIdx = e.currentTarget.dataset.index;
const currentSecondvalue = e.currentTarget.dataset.value;
this.setData({
    currentSecondIdx_position: currentSecondIdx,
    currentSecondvalue_position: currentSecondvalue
})
},
get_position(){
  const that = this
  const dataList_position = that.data.dataList_position
  var first_position = []
  for(let item in dataList_position){
    first_position.push(item)
  }
  const orignFirstValue_position = first_position[0];
    var secondList_position = that.data.dataList_position[orignFirstValue_position];
    if(secondList_position==undefined)
    {
        secondLis_position=[]
    }
    const orignSecondValue_position = secondList_position[0];

    // 在组件实例进入页面节点树时执行
    this.setData({
        firstList_position: first_position,
        secondList_position: secondList_position,

        orignFirstIdx_position: 0,
        orignFirstValue_position: orignFirstValue_position,
        orignSecondIdx_area: 0,
        orignSecondValue_position: orignSecondValue_position,

        currentFirstvalue_position: orignFirstValue_position,
        currentSecondvalue_position: orignSecondValue_position,


    })
},
  onLoad:async function (options) {
    const { bottom } = wx.getMenuButtonBoundingClientRect()
    const navigationBarBottom = 2 * bottom + 12
    const that = this
    var curPosition = getApp().globalData.currentPos
    console.log("ddd:",curPosition)
    if(curPosition.province == undefined || curPosition.province == ""){
      curPosition.province = "广东省"
    }
    if(curPosition.city == undefined || curPosition.city == ""){
      curPosition.city = "广州市"
    }
    this.setData({
      curPosition: getApp().globalData.currentPos,
      bottomSafe: 2 * wx.getStorageSync('bottomSafe'), // 安全距离
      navigationBarBottom,
      listHeight1: `height: calc(100vh - ${280 + navigationBarBottom}rpx)`,
      listHeight2: `height: calc(100vh - ${176 + navigationBarBottom}rpx)`,
      nav1Padding1: `padding-top: ${192 + navigationBarBottom}rpx`,
      nav1Padding2: `padding-top: ${88 + navigationBarBottom}rpx`,
      nav2Padding1: `padding-top: ${280 + navigationBarBottom}rpx`,
      nav2Padding2: `padding-top: ${192 + navigationBarBottom}rpx`,
    })
    this.selectComponent('#navigationBar').getMenuButtonRect()
    //获取地域信息
    var temp = await wx.$cloud.callFunction({
      name: 'getCityInf',
      data: {
          action: "getAllInfo",
      }
  })
  temp = temp.result
  var dataList_area = {}
  dataList_area["不限"] = []
  for (let i = 0; i < temp.length; i++) {
      dataList_area[temp[i].city + '市'] = temp[i].area
  }
  //设置dataList_area
  this.setData({
      dataList_area: dataList_area,
  })
  var firstList = []
  for (let item in dataList_area) {
    firstList.push(item);
}
this.setData({
  firstList: firstList,
  currentFirstvalue: "不限",
  currentSecondvalue: ""
})
//初始化岗位信息
this.get_position()
this.get_teacherList_onLoad()
    //this.getLists()
    // wx.$cloud.callFunction({
    //   name: 'return-recruit-info',
    //   data: {
    //     action: 'return',
    //     size:10
    //   },
    //   success: res => {
    //     this.setData({
    //       list : res.result.data
    //     })
    //   }
    // })
  },
  /**
     * 返回上一页
     */
  goBack:function(){
    wx.navigateBack({
      delta: 0,
    }) 
  },

  /**
   * 职位列表滚动监听
   */
  scrollList(e) {
    const { scrollTop } = e.detail
    if (scrollTop > 100 && this.data.showSearch) {
      this.setData({
        showSearch: false,
      })
    }
  },
  /**
   * 展示搜索框
   */
  showSearch() {
    this.setData({
      showSearch: true,
    })
  },

  /**
   * 展示排序弹窗
   */
  showSort() {
    this.setData({
      showSort: !this.data.showSort,
    })
  },
  /**
   * 关闭排序弹窗
   */
  closeshowSort() {
    this.setData({
      showSort: false,
    })
  },
  /**
   * 更换排序
   */
  changeSortActivate(e) {
    const { key } = e.currentTarget.dataset
    this.setData({
      sortActivate: key,
    })
  },

  /**
   * 更换nav2
   */
  changeNav2Activate(e) {
    const { key } = e.currentTarget.dataset
    this.setData({
      nav2Activate: this.data.nav2Activate === key ? -1 : key,
    })
  },
  /**
   * 关闭nav2弹窗
   */
  closeNav2Sort() {
    this.setData({
      nav2Activate: -1,
    })
  },
  /**
   * 监听输入
   */
  bindKeyInput(e) {
    this.setData({
        inputValue: e.detail.value
    })
},
  /**
   * 修改区域
   */
  changepositionChoose(e) {
    const { key, type } = e.currentTarget.dataset
    const keyName = type === '1' ? 'positionChoose.one' : 'positionChoose.two'
    this.setData({
      [keyName]: key,
    })
  },
  /**
   * 修改岗位
   */
  changeregionChoose(e) {
    const { key, type } = e.currentTarget.dataset
    const keyName = type === '1' ? 'regionChoose.one' : 'regionChoose.two'
    this.setData({
      [keyName]: key,
    })
  },

  /**
   * 修改编制
   */
  changeOrganization(e) {
    const { key } = e.currentTarget.dataset
    const keyName = 'organizationList[0].key'
    console.log("keyname:",keyName)
    console.log("key:",key)
    this.setData({
      [keyName]: key,
    })
  },
  /**
   * 修改更多
   */
  changeMore(e) {
    const { key, index } = e.currentTarget.dataset
    const keyName = `moreList[${index}].key`
    console.log("keyname:",keyName)
    console.log("key:",key)
    this.setData({
      [keyName]: key,
    })
  },

  /**
   * 重置筛选弹窗
   */
  reset(e) {
    const { type } = e.currentTarget.dataset
    const that = this
    switch (type) {
      case 'region':
        const currentFirstIdx = 0
        const currentFirstvalue= that.data.firstList[0]
        const secondList= that.data.dataList_area[currentFirstvalue] != undefined ? [] : that.data.dataList_area[currentFirstvalue]
        const currentSecondIdx = 0
        const currentSecondvalue = secondList[0]
        this.setData({
          isReset: true,
          regionChoose: {
            one: 1,
            two: 1,
          },
        currentFirstIdx: currentFirstIdx,
        currentFirstvalue: currentFirstvalue,
        secondList: secondList,
        currentSecondIdx: currentSecondIdx,
        currentSecondvalue: currentSecondvalue
        })
        break
      case 'position':
        const currentFirstIdx_position = 0
        const currentFirstvalue_position = that.data.firstList_position[0]
        const secondList_position = that.data.dataList_position[currentFirstvalue_position] != undefined ? [] : that.data.dataList_position[currentFirstvalue_position]
        const currentSecondIdx_position = 0
        const currentSecondvalue_position = secondList_position[0]
        this.setData({
          isReset: true,
          positionChoose: {
            one: 1,
            two: 1,
          },
        currentFirstIdx_position: currentFirstIdx_position,
        currentFirstvalue_position: currentFirstvalue_position,
        secondList_position: secondList_position,
        currentSecondIdx_position: currentSecondIdx_position,
        currentSecondvalue_position: currentSecondvalue_position
        })
        break
      case 'organization':
        const keyName = 'organizationList[0].key'
        this.setData({
          [keyName]: '不限编制',
        })
        break
      case 'more':
        const moreList = this.data.moreList.map((item) => {
          item.key = item.children[0].name
          return item
        })
        this.setData({
          moreList,
        })
        break
      default:
        break
    }
  },
  //判断该字段是否有传的必要
  conclZiduan(target){
    if(target != undefined && target != "" && target.indexOf("不限")==-1){
      return true
    }
    return false
  },
  /**
   * 确认筛选修改
   */
  confirm(e) {
    //判断是否超过查看次数
    if(util.conclLook() == false){
      return ;
    }
    //同时把搜索状态置False
    this.setData({
      no_more: false,
      searched: false
    })
    const { type } = e.currentTarget.dataset
    const that = this
    switch (type) {
      case 'region':
        console.log("---data:",that.data)
        const region1 = that.data.currentFirstvalue
        const region2 = that.data.currentSecondvalue==undefined?"":
        that.data.currentSecondvalue
        const region = region1 + '/' + region2
        that.setData({
          region,
          nav2Activate: -1,
        })
        break
      case 'position':
        const { one: one1, two: two2 } = this.data.positionChoose
        const positon1 = that.data.currentFirstvalue_position
        const positon2 = that.data.currentSecondvalue_position==undefined?"":
        that.data.currentSecondvalue_position
        const position = positon1 + '/' + positon2
        this.setData({
          position,
          nav2Activate: -1,
        })
        break
      case 'organization':
        this.setData({
          nav2Activate: -1,
        })
        break
      case 'more':
        this.setData({
          nav2Activate: -1,
        })
        break
      default:
        break
    }
    //重置step
    this.setData({
      step: 0
    })
    console.log("筛选确定后的字段：",this.data)
    const data = that.data
    var filter = that.data.filterOptions
    //确定地域的筛选
    if(this.conclZiduan(data.currentFirstvalue)){
      filter.city = data.currentFirstvalue
    }else{
      filter.city = ""
    }
    if(this.conclZiduan(data.currentSecondvalue)){
      filter.district = data.currentSecondvalue
    }else{
      filter.district = ""
    }
    //判断岗位等级的筛选
    if(this.conclZiduan(data.currentFirstvalue_position)){
      filter.post_level = data.currentFirstValue_position
    }else{
      filter.post_level = ""
    }
    if(this.conclZiduan(data.currentSecondvalue_position)){
      filter.subject = data.currentSecondvalue_position
    }else{
      filter.subject = ""
    }
    //判断报名方式
    if(this.conclZiduan(data.moreList[1].key)){
      filter.registration_way = data.moreList[1].key
    }else{
      filter.registration_way = ""
    }
    //判断是否编制
    if(this.conclZiduan(data.organizationList[0].key)){
      filter.has_organized = data.organizationList[0].key
    }else{
      filter.has_organized = ""
    }
    //判断报名阶段
    if(this.conclZiduan(data.moreList[2].key)){
      filter.stage = data.moreList[2].key
    }else{
      filter.stage = ""
    }
    //判断发布时间
    const time = data.moreList[0].key
    if(this.conclZiduan(time)){
        if (time == '不限时间') {
          filter.choosetime = 0
      } else if (time == '今天') {
        filter.choosetime = 1
      } else if (time == '近一周') {
        filter.choosetime = 7
      } else if (time == '近一个月') {
        filter.choosetime = 30
      } else if (time == '近三个月') {
        filter.choosetime = 90
      } else if (time == '近一年') {
        filter.choosetime = 360
      }
    }else{
      filter.choosetime = 0
    }
    that.setData({
      filterOptions: filter
    })
    console.log("筛选的字段：",that.data.filterOptions)
      wx.$cloud.callFunction({
        name: 'return-recruit-info',
        data: {
            action: 'return',
            size: this.data.size,
            step: this.data.step,
            ...this.data.filterOptions
        }
    }).then(
        res => {
            console.log('筛选确定后返回结果:', res)
            for(let i = 0;i< res.result.data.length ; i++){
              res.result.data[i].registration_begin = this.format(res.result.data[i].registration_begin)
              res.result.data[i].registration_end = this.format(res.result.data[i].registration_end)
            }
            this.setData({
                list: res.result.data,
                step: this.data.step + this.data.size,
            })
        }
    )

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    const that = this
    if (this.data.no_more === true) {
        console.log('没有更多数据!')
        return
    }
    //判断当前是否处于搜索状态
    if(this.data.searched){
       wx.$cloud.callFunction({
        name: "return-recruit-info",
        data: {
            action: 'search',
            search: this.data.inputValue,
            size: this.data.size,
            step: that.data.step
        }
    }).then(
        res => {
            if (res.result.data.length == 0) { //若没找到或出错
                this.setData({
                  list: [],
                  no_more: true
                })
            } else {
              for(let i = 0;i< res.result.data.length ; i++){
                res.result.data[i].registration_begin = this.format(res.result.data[i].registration_begin)
                res.result.data[i].registration_end = this.format(res.result.data[i].registration_end)
              }
                this.setData({
                  list: [...that.data.list, ...res.result.data],
                        step: that.data.step + that.data.size
                })
            }
        }
    )
    return;
    }
    // 判断当前是否有筛选条件
    var filted = false
    const filterOptionsKeys = Object.keys(this.data.filterOptions)
    filterOptionsKeys.forEach(k => {
        if (k != 'choosetime')
            if (this.data.filterOptions[k])
                filted = true
    })
    // 未筛选时使用getPost接口
    var cloudOptions = {
        name: 'getPost',
        data: {
            Action: 'getPosts',
            province: this.data.curPosition.province,
            city: this.data.curPosition.city,
            skip: this.data.step,
            size: this.data.size,
        },
    }
    // 有筛选时使用return-recruit-info接口
    if (filted)
        cloudOptions = {
            name: 'return-recruit-info',
            data: {
                action: 'return',
                size: this.data.size,
                step: this.data.step,
                ...this.data.filterOptions
            }
        }
    wx.$cloud.callFunction({
        ...cloudOptions
    }).then(
        res => {
            if (res.result.error != 0) { //若返回不为空
              for(let i = 0;i< res.result.data.length ; i++){
                res.result.data[i].registration_begin = this.format(res.result.data[i].registration_begin)
                res.result.data[i].registration_end = this.format(res.result.data[i].registration_end)
              }
                this.setData({
                    list: [...this.data.list, ...res.result.data],
                    step: this.data.step + this.data.size
                })
            } else { //否则，没有更多结果了,设置no_more为真
                this.setData({
                    no_more: true
                })
            }

        }
    )
  },
  //跳去搜索
  async JumpToSearch(){
    //判断是否超过查看次数
    if(util.conclLook() == false){
      return ;
    }
    const that = this
    if(this.data.inputValue == ""){
      console.log("没有输入搜索内容")
      return
    }
    this.setData({
      step: 0,
      no_more: false,
      searched: true
    })
    await wx.$cloud.callFunction({
      name: "return-recruit-info",
      data: {
          action: 'search',
          search: this.data.inputValue,
          size: this.data.size,
          step: 0
      }
  }).then(
      res => {
          if (res.result.data.length == 0) { //若没找到或出错
              this.setData({
                list: [],
                no_more: true
              })
          } else {
            for(let i = 0;i< res.result.data.length ; i++){
              res.result.data[i].registration_begin = this.format(res.result.data[i].registration_begin)
              res.result.data[i].registration_end = this.format(res.result.data[i].registration_end)
            }
              this.setData({
                list: res.result.data,
                step: that.data.step+ that.data.size
              })
          }
          console.log('serach@@@@@@@@@@@@@@@@@@@@@@', res)

      }
  )
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},

  //请求teacherList
  get_teacherList_onLoad() {
    const that = this
    console.log("position:", this.data.curPosition)
    wx.$cloud.callFunction({
        name: "getPost",
        data: {
            Action: 'getPosts',
            province: that.data.curPosition.province,
            city: that.data.curPosition.city,
            skip: 0,
            size: that.data.size
        },
    }).then(
        res => {
          // props.registration_begin = this.format(props.registration_begin)
          // props.registration_end = this.format(props.registration_end)
          for(let i = 0;i< res.result.data.length ; i++){
            res.result.data[i].registration_begin = this.format(res.result.data[i].registration_begin)
            res.result.data[i].registration_end = this.format(res.result.data[i].registration_end)
          }
            this.setData({
                list: res.result.data,
                step: this.data.step + this.data.size
            })
            console.log(this.data.teacherList)
            //判断是否还有更多结果
            if (res.error === 0) {
              console.log("??????????????????????????")
                this.setData({
                    no_more: true
                })
            }
        }
    )
},
format:function(release_time) {
  const time_a = util.formatTime(new Date(release_time)) //此时得到形如2021-11-23
  // console.log(time_a)
  const year = time_a.substr(0, 4)
  let month = time_a.substr(5, 2)
  let day = time_a.substr(8, 2)
  //去掉前导0
  if (month[0] == '0') {
    month = month.substring(1)
  }
  if (day[0] == '0') {
    day = day.substring(1)
  }
  const time_b = year + '-' + month + "-" + day  //此时得到形如2021-11-23
  // console.log(time_b)
  return time_b;
},

})
